<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\Wechat;
use Illuminate\Support\Facades\Log;

class WechatLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = session('wechat.oauth_user.default'); // 拿到授权用户资料
        Log::error('wechat user');
        Log::error($user);

        $stock = User::where('openid', $user->openid)->first();

        if (!$stock) {
            return response()->json(['code'=>40001,'msg'=>'请从微信打开连接']);
        }

        return $next($request);
    }
}
